import {
  imageUrl
} from "../../utils/imageutil"
import {
  network
} from "../../utils/api"
import {
  zfb_pay_code
} from "../../utils/save_share_pic"
Component({


  properties: {
    show_code_img: {
      type: Boolean,
      value: false
    },
  },


  data: {
    imageUrl,
    code_img: '',
  },

  lifetimes: {
    attached: function () {
      // 在组件实例进入页面节点树时执行
      this.get_code()
    },
  },

  methods: {
    close() {
      this.setData({
        show_code_img: false
      })
    },
    get_code(title='') {
      title = encodeURIComponent(title)
      let code_img = network + `?i=5&from=wxapp&c=entry&a=wxapp2&m=zh_cjdianc&do=alipay&url=${title}`
      this.setData({
        code_img,
      })
    },
    bottomTap() {
      let that = this;
      wx.getSetting({
        success(res) {
          if (res.authSetting['scope.writePhotosAlbum'] == false) {
            //没有授权
            wx.openSetting();
          } else if (res.authSetting['scope.writePhotosAlbum'] == true) {
            //授权了
            zfb_pay_code("myCanvas", that, that.data.imageUrl + '/index/zfb_bg.png', that.data.code_img)
          } else {
            zfb_pay_code("myCanvas", that, that.data.imageUrl + '/index/zfb_bg.png', that.data.code_img)
          }
        }
      })
    },
  }
})